package com.sohu.sip.group.impl;

import java.io.Serializable;

/**
 * A notification message that holds information about a cache event. This
 * class is <code>Serializable</code> to allow it to be sent across the
 * network to other machines running in a cluster.
 *
 * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
 * @author $Author: chenweiwei $
 * @version $Revision: 1.1 $
 */
public class ClusterNotification implements Serializable {
    /**
     * Specifies a notification message that indicates a particular cache key
     * should be flushed.
     */
    public static final int FLUSH_KEY = 1;

    /**
     * Specifies a notification message that indicates an entire cache group
     * should be flushed.
     */
    public static final int FLUSH_GROUP = 2;

    /**
     * Specifies a notification message that indicates all entries in the cache
     * that match the specified pattern should be flushed.
     */
    public static final int FLUSH_PATTERN = 3;

    /**
     * Specifies a notification message indicating that an entire cache should
     * be flushed.
     */
    public static final int FLUSH_CACHE = 4;

	private String key;

	private String region;

    /**
     * The type of notification message.
     */
    protected int type;

    /**
     * Creates a new notification message object to broadcast to other
     * listening nodes in the cluster.
     *
     * @param type       The type of notification message. Valid types are
     *                   {@link #FLUSH_KEY} and {@link #FLUSH_GROUP}.
     * @param region       Specifies the object key or group name to flush.
     * @param key       Specifies the object key or group name to flush.
     */
    public ClusterNotification(int type, String region, String key) {
        this.type = type;
		this.key = key;
		this.region = region;
    }

	/**
	 * @return Returns the key.
	 */
	public String getKey() {
		return key;
	}

	/**
	 * @return Returns the region.
	 */
	public String getRegion() {
		return region;
	}
    /**
     * The type of notification message.
     */
    public int getType() {
        return type;
    }

    public String toString() {    	
    	StringBuffer buf = new StringBuffer();
        buf.append("region=").append(region).append(", key=").append(key).append(", type=").append(type);

        return buf.toString();
    }
}
